package com.aliyun.heiyu.common.source;

import com.aliyun.heiyu.common.util.JdbcUtil;

import java.sql.SQLException;
import java.util.List;

public class PskImpl implements PskDao {
    @Override
    public List<Psktable> findAll() {
        String sql = "SELECT  * FROM t_pskey WHERE 1=1";
        return JdbcUtil.queryForList(sql+ "order by id desc",null,Psktable.class);
    }

    @Override
    public Psktable findOne(String Id) {
        String sql="SELECT * FROM t_pskey WHERE 1= 1 and id = ?";
        Object[] kk = new Object[1];
        if(null==Id){
            kk[0] =1;
        }else{
            kk[0] = Id;
        }
        Psktable result = JdbcUtil.queryForBean(sql, kk, Psktable.class);
        return result;
    }

    @Override
    public boolean insert(Psktable entity) throws SQLException {
        String sql = "insert into t_pskey(id,pkey,skey,type,state,deviceType,alarm_level) values (?,?,?,?,?,?,?)";
        Object[] kk = new Object[4];
        kk[0]=entity.getId();
        kk[1]=entity.getPkey();
        kk[2]=entity.getSkey();
        kk[3]=entity.getType();
        boolean result = JdbcUtil.update(sql, kk);
        return result;
    }

    @Override
    public boolean update(Psktable entity) throws SQLException {
        String sql = "update t_pskey set pkey = ?,skey = ? where id = ?";
        Object[] kk = new Object[3];
        kk[0]=entity.getPkey();
        kk[1]=entity.getSkey();
        kk[2] = entity.getId();
        boolean result = JdbcUtil.update(sql, kk);
        return result;
    }

}
